package com.yangye.piconfig.handler;

import com.yangye.picommon.exception.PiException;
import com.yangye.picommon.model.PiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yangye
 * @date 2019/8/1
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

	/**
	 * 自定义异常处理
	 * @param e
	 * @return
	 */
	@ExceptionHandler(PiException.class)
	@ResponseBody
	PiResult exceptionHandler(PiException e) {
		log.error(e.getMessage(), e);
		return PiResult.fail(e.getMessage());
	}
}
